#!/bin/bash


############### function ############

start_server()
{
    echo "running $1 ..."
    $1 -d
    sleep 2
    
}


stop_server()
{
    echo "stopping $1 ..."
    pkill -USR2 -f $1
    sleep 3
}


server_list="connectorsvrd gateway router gameserver_dbg worldserver_dbg"

start_all()
{
    for server in $server_list ; do
        start_server $(pwd)/$server
    done
}


stop_all()
{
    for server in $server_list ; do
        stop_server $(pwd)/$server
    done

    
}


############## main ################

if [ $# -lt 1 ] ; then 
    echo "usage:$0 start|stop"
    exit
fi

command="$1"
echo "prepare execute [$command] ..."

cd $(dirname $0)
base_dir=$(pwd)
echo "change dir to [$base_dir] "
cd $base_dir

case "$command" in
    start)
        start_all
    ;;
    stop)
        stop_all
    ;;
esac

echo "done execute [$command]"
